]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
misc/dbusUtils: Add function to emit a signal to a specific bus
authorMarco Trevisan (Treviño) <mail@3v1n0.net>
Wed, 20 May 2026 15:14:43 +0000 (17:14 +0200)
committerFlorian Müllner <fmuellner@gnome.org>
Sun, 13 Sep 2026 17:39:10 +0000 (19:39 +0200)
Gjs's dbus skeleton implementation does not allow to send a signal to a
specific object only, and while this is an API addition we should do, in
the shell we were repeating the same pattern multiple times.

So let's add an utility function that does that, rather than replicating
the same multiple times.

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/4270>
(cherry picked from commit 1cde9840ee14338936d06e484f14fb7d00729160)

js/dbusServices/notifications/notificationDaemon.js
js/misc/dbusUtils.js
js/ui/audioDeviceSelection.js
js/ui/shellDBus.js

index d6ef17a0d0de6228b6fd65f05ebb4544bf3b898b..108372b8a2a9a9c484be0d51ad0cb5ac99d0d235 100644 (file)
@@ -3,7 +3,7 @@ import GLib from 'gi://GLib';
 
 import {ServiceImplementation} from './dbusService.js';
 
-import {loadInterfaceXML} from './misc/dbusUtils.js';
+import {emitSignalToDestination, loadInterfaceXML} from './misc/dbusUtils.js';
 
 const NotificationsIface = loadInterfaceXML('org.freedesktop.Notifications');
 const NotificationsProxy = Gio.DBusProxy.makeProxyWrapper(NotificationsIface);
@@ -56,12 +56,7 @@ export const NotificationDaemon = class extends ServiceImplementation {
     _emitSignal(sender, signalName, params) {
         if (!sender)
             return;
-        this._dbusImpl.get_connection()?.emit_signal(
-            sender,
-            this._dbusImpl.get_object_path(),
-            'org.freedesktop.Notifications',
-            signalName,
-            params);
+        emitSignalToDestination(this._dbusImpl, sender, signalName, params);
     }
 
     _untrackSender(sender) {
index 8360b303f1489e79fa25eab4264dc1955eb1362c..73881acecfed7d54a416ecbeb594325c066a310f 100644 (file)
@@ -65,3 +65,22 @@ export function loadSubInterfaceXML(iface, ifaceFile) {
         xml.substring(ifaceStartIndex, ifaceEndIndex) +
         xmlFooter);
 }
+
+/**
+ * Emits a D-Bus signal to the given destination bus name.
+ *
+ * @param {Gio.DBusInterfaceSkeleton} dbusImpl - The D-Bus implementation
+ * @param {string|null} destination - The destination bus name or null
+ * @param {string} signalName - The signal name
+ * @param {GLib.Variant|null} params - The signal parameters or null
+ */
+export function emitSignalToDestination(dbusImpl, destination, signalName, params) {
+    const connection = dbusImpl.get_connection();
+    const info = dbusImpl.get_info();
+    connection.emit_signal(
+        destination,
+        dbusImpl.get_object_path(),
+        info?.name ?? null,
+        signalName,
+        params);
+}
index d0e92816e74ecde241bfcd50c4e7aa4d5cf6c8d5..b66ecf22c737616e133481722234944215c11a5a 100644 (file)
@@ -10,6 +10,7 @@ import * as Dialog from './dialog.js';
 import * as ModalDialog from './modalDialog.js';
 
 import * as Main from './main.js';
+import {emitSignalToDestination} from '../misc/dbusUtils.js';
 import {loadInterfaceXML} from '../misc/fileUtils.js';
 
 const AudioDevice = {
@@ -165,15 +166,11 @@ export class AudioDeviceSelectionDBus {
     }
 
     _onDeviceSelected(dialog, device) {
-        const connection = this._dbusImpl.get_connection();
-        const info = this._dbusImpl.get_info();
         const deviceName = Object.keys(AudioDevice)
             .filter(dev => AudioDevice[dev] === device)[0].toLowerCase();
-        connection.emit_signal(
-            this._audioSelectionDialog._sender,
-            this._dbusImpl.get_object_path(),
-            info ? info.name : null,
-            'DeviceSelected',
+
+        emitSignalToDestination(this._dbusImpl,
+            this._audioSelectionDialog._sender, 'DeviceSelected',
             GLib.Variant.new('(s)', [deviceName]));
     }
 
index 1e5a6a3226b4051b2a82f4e8b66ae5fb20a43c85..89aa982f9a663740bccba47f90ed89c8bfc7aa90 100644 (file)
@@ -9,6 +9,7 @@ import * as ExtensionUtils from '../misc/extensionUtils.js';
 import * as Main from './main.js';
 import * as Screenshot from './screenshot.js';
 
+import {emitSignalToDestination} from '../misc/dbusUtils.js';
 import {loadInterfaceXML} from '../misc/fileUtils.js';
 import {DBusSenderChecker} from '../misc/util.js';
 import {ControlsState} from './overviewControls.js';
@@ -284,9 +285,6 @@ export class GnomeShell {
         if (!destination)
             return;
 
-        const connection = this._dbusImpl.get_connection();
-        const info = this._dbusImpl.get_info();
-
         const context = global.create_app_launch_context(0, -1);
         const token = context.get_startup_notify_id(null, []);
 
@@ -300,10 +298,9 @@ export class GnomeShell {
         if (deviceNode)
             params['device-node'] = GLib.Variant.new('s', deviceNode);
 
-        connection.emit_signal(
+        emitSignalToDestination(
+            this._dbusImpl,
             destination,
-            this._dbusImpl.get_object_path(),
-            info?.name ?? null,
             signal,
             GLib.Variant.new('(ua{sv})', [action, params]));
     }